package com.lesso.yjy.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.yjy.sunflower.domain.repository.DeviceRepository;
import com.lesso.yjy.sunflower.infra.assembler.DeviceAssembler;
import com.lesso.yjy.sunflower.model.Device;
import com.lesso.yjy.sunflower.pojo.dto.DeviceDTO;
import com.lesso.yjy.sunflower.pojo.dto.DeviceQueryDTO;
import com.lesso.yjy.sunflower.pojo.vo.DeviceVO;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class DeviceDomainService {
    private final DeviceRepository deviceRepository;

    private DeviceDomainService(DeviceRepository deviceRepository){
        this.deviceRepository = deviceRepository;
    }

    public Long save(DeviceDTO dto){
        return deviceRepository.save(DeviceAssembler.INSTANCE.dtoToEntity(dto));
    }

    public Page<DeviceVO> page(DeviceQueryDTO dto){
        return deviceRepository.getPageList(dto);
    }

    public Page<DeviceVO> customPage(DeviceQueryDTO dto){
        return deviceRepository.getCustomPageList(dto);
    }

    public void deleteById(Long id){
        deviceRepository.removeById(id);
    }

    public void update(DeviceDTO dto){
        deviceRepository.updateById(dto);
    }
}
